Skip to content

Aggregation query method should be able to return Slice and Stream #3645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

divyajnu08
Copy link
Contributor

…f you pass Pageable and Sort

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@divyajnu08
Copy link
Contributor Author

Hi Mark ,
I have made the changes , now aggregation will return a Slice if pageable is passed.
Kindly check.
Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 6, 2021

List mappedResults = result.getMappedResults();

if(method.isPageQuery() || method.isSliceQuery()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a slight difference between Page and Slice. Paging is aware of the total amount of items while slice requests pageSize+1 to determine whether there's a next slice available.

Probably paging becomes more difficult because we have to issue a count query and that kind-of imposes performance questions when a complex aggregation is used.

For the time being, let's consider only Slice and I'm going to raise the issue with our team to discuss the performance aspect when someone wants to use Page<T>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done the changes

@mp911de mp911de added the for: team-attention An issue we need to discuss as a team to make progress label May 7, 2021
@mp911de
Copy link
Member

mp911de commented May 7, 2021

Returning a Page indeed doesn't make sense as the computation overhead for aggregations outweighs the benefits. The aggregation would require wrapping with a counting stage and would be executed twice. So we will stick with what we have in this pull request.

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 7, 2021
@mp911de mp911de self-assigned this May 7, 2021
@mp911de mp911de changed the title Issue-3543 - Aggregation annotation should be able to return a Page i… Aggregation query method should be able to return Slice and Stream May 11, 2021
@mp911de mp911de linked an issue May 11, 2021 that may be closed by this pull request
@mp911de mp911de removed the for: team-attention An issue we need to discuss as a team to make progress label May 11, 2021
@mp911de mp911de added this to the 3.3 M1 (2021.1.0) milestone May 11, 2021
mp911de pushed a commit that referenced this pull request May 11, 2021
Aggregation query methods can not return Slice and Stream.

interface PersonRepository extends CrudReppsitory<Person, String> {

  @Aggregation("{ $group: { _id : $lastname, names : { $addToSet : ?0 } } }")
  Slice<PersonAggregate> groupByLastnameAnd(String property, Pageable page);

  @Aggregation("{ $group: { _id : $lastname, names : { $addToSet : $firstname } } }")
  Stream<PersonAggregate> groupByLastnameAndFirstnamesAsStream();
}

Closes #3543.
Original pull request: #3645.
mp911de added a commit that referenced this pull request May 11, 2021
Let appendLimitAndOffsetIfPresent accept unary operators for adjusting limit/offset values instead of appendModifiedLimitAndOffsetIfPresent. Apply simple type extraction for Slice. Add support for aggregation result streaming.

Extend tests, add author tags, update docs.

See #3543.
Original pull request: #3645.
@mp911de
Copy link
Member

mp911de commented May 11, 2021

Thank you for your contribution. That's merged and polished now. I added also support for Stream.

@mp911de mp911de closed this May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aggregation query method should be able to return Slice and Stream
3 participants